<?xml version="1.0" encoding="utf-8" ?> 
<sqlMap namespace="Order"
	xmlns="http://ibatis.apache.org/mapping" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<alias>
		<typeAlias alias="Order" type="Domain.Order" />
	</alias>

	<resultMaps>
		<resultMap id="FullResultMap" class="Order">
			<result property="orderId" column="orderId" dbType="Int"/>
			<result property="userId" column="userId" dbType="Int"/>
			<result property="payType" column="payType" dbType="NVarChar"/>
			<result property="provinceId" column="provinceId" dbType="Int"/>
			<result property="cityId" column="cityId" dbType="Int"/>
			<result property="receiverName" column="receiverName" dbType="NVarChar"/>
			<result property="receiverSex" column="receiverSex" dbType="Int"/>
			<result property="receiverAddress" column="receiverAddress" dbType="NVarChar"/>
			<result property="receiverPostCode" column="receiverPostCode" dbType="NVarChar"/>
			<result property="receiverTelephone" column="receiverTelephone" dbType="NVarChar"/>
			<result property="receiverMobile" column="receiverMobile" dbType="NVarChar"/>
			<result property="receiverEmail" column="receiverEmail" dbType="NVarChar"/>
			<result property="receiverIsSameToUser" column="receiverIsSameToUser" dbType="Bit"/>
			<result property="orderRemark" column="orderRemark" dbType="NVarChar"/>
			<result property="orderTime" column="orderTime" dbType="SmallDateTime"/>
			<result property="replyContent" column="replyContent" dbType="NVarChar"/>
			<result property="replyTime" column="replyTime" dbType="SmallDateTime"/>
			<result property="financeStatus" column="financeStatus" dbType="NVarChar"/>
			<result property="technicStatus" column="technicStatus" dbType="NVarChar"/>
			<result property="schedule" column="schedule" dbType="NVarChar"/>
			<result property="deleteFlag" column="deleteFlag" dbType="Int"/>
			<result property="deadlineTime" column="deadlineTime" dbType="SmallDateTime"/>
			<result property="gongchengdizhi" column="gongchengdizhi" dbType="NVarChar"/>
      <result property="orderCode" column="orderCode" dbType="NVarChar"/>
		</resultMap>
	</resultMaps>
	
	<statements>

		<select id="GetCount" resultClass="System.Int32">
			SELECT count(*) FROM [dbo].[order]
		</select>
		
		<select id="GetCountByCondition" parameterClass="Hashtable" resultClass="System.Int32" extends="GetCount">
			WHERE $condition$
		</select>
		
		<select id="FindAll" resultClass="Order">
			SELECT * 
			FROM [dbo].[order]
		</select>
		
		<select id="GetModel" parameterClass="Order" resultClass="Order" extends="FindAll">
			WHERE
				([order].[orderId] = #orderId,dbType=Int#)
		</select>

		<insert id="Insert" parameterClass="Order">
      INSERT INTO [dbo].[order] (

      [userId] ,
      [payType] ,
      [provinceId] ,
      [cityId] ,
      [receiverName] ,
      [receiverSex] ,
      [receiverAddress] ,
      [receiverPostCode] ,
      [receiverTelephone] ,
      [receiverMobile] ,
      [receiverEmail] ,
      [receiverIsSameToUser] ,
      [orderRemark] ,
      [orderTime] ,
      [replyContent] ,
      [financeStatus] ,
      [technicStatus] ,
      [schedule] ,
      [deleteFlag] ,
      [gongchengdizhi],
      [orderCode]
      ) VALUES (

      #userId,dbType=Int# ,
      #payType,dbType=NVarChar# ,
      #provinceId,dbType=Int# ,
      #cityId,dbType=Int# ,
      #receiverName,dbType=NVarChar# ,
      #receiverSex,dbType=Int# ,
      #receiverAddress,dbType=NVarChar# ,
      #receiverPostCode,dbType=NVarChar# ,
      #receiverTelephone,dbType=NVarChar# ,
      #receiverMobile,dbType=NVarChar# ,
      #receiverEmail,dbType=NVarChar# ,
      #receiverIsSameToUser,dbType=Bit# ,
      #orderRemark,dbType=NVarChar# ,
      #orderTime,dbType=SmallDateTime# ,
      #replyContent,dbType=NVarChar# ,
      #financeStatus,dbType=NVarChar# ,
      #technicStatus,dbType=NVarChar# ,
      #schedule,dbType=NVarChar# ,
      #deleteFlag,dbType=Int# ,
      #gongchengdizhi,dbType=NVarChar#,
      #orderCode,dbType=NVarChar#
      )
      <selectKey property="orderId" resultClass="int" type="post">
        select @@identity as value
      </selectKey>
		</insert>
    <update id="SetStatusInDetail" parameterClass="Order">
      UPDATE [dbo].[order] SET
      [deleteFlag] = #deleteFlag,dbType=Int#,
      [financeStatus] = #financeStatus,dbType=NVarChar# ,
      [technicStatus] = #technicStatus,dbType=NVarChar# 
      <isParameterPresent>
        ,[deadlineTime] = #deadlineTime,dbType=SmallDateTime#
      </isParameterPresent>
      
      WHERE
      ([orderId] = #orderId,dbType=Int#)
    </update>

    <update id="SetStatus" parameterClass="Order">
      UPDATE [dbo].[order] SET
      [deleteFlag] = #deleteFlag,dbType=Int#
      WHERE
      ([orderId] = #orderId,dbType=Int#)
    </update>
    
		<update id="Update" parameterClass="Order">
      UPDATE [dbo].[order] SET
      [userId] = #userId,dbType=Int#
      , [payType] = #payType,dbType=NVarChar#
      , [provinceId] = #provinceId,dbType=Int#
      , [cityId] = #cityId,dbType=Int#
      , [receiverName] = #receiverName,dbType=NVarChar#
      , [receiverSex] = #receiverSex,dbType=Int#
      , [receiverAddress] = #receiverAddress,dbType=NVarChar#
      , [receiverPostCode] = #receiverPostCode,dbType=NVarChar#
      , [receiverTelephone] = #receiverTelephone,dbType=NVarChar#
      , [receiverMobile] = #receiverMobile,dbType=NVarChar#
      , [receiverEmail] = #receiverEmail,dbType=NVarChar#
      , [receiverIsSameToUser] = #receiverIsSameToUser,dbType=Bit#
      , [orderRemark] = #orderRemark,dbType=NVarChar#
      , [orderTime] = #orderTime,dbType=SmallDateTime#
      , [replyContent] = #replyContent,dbType=NVarChar#
      , [replyTime] = #replyTime,dbType=SmallDateTime#
      , [financeStatus] = #financeStatus,dbType=NVarChar#
      , [technicStatus] = #technicStatus,dbType=NVarChar#
      , [schedule] = #schedule,dbType=NVarChar#
      , [deleteFlag] = #deleteFlag,dbType=Int#
      , [deadlineTime] = #deadlineTime,dbType=SmallDateTime#
      , [gongchengdizhi] = #gongchengdizhi,dbType=NVarChar#
      WHERE
      ([orderId] = #orderId,dbType=Int#)
    </update>
    <update id="Reply" parameterClass="Order">
      UPDATE [dbo].[order] SET
       [replyContent] = #replyContent,dbType=NVarChar#
      , [replyTime] = #replyTime,dbType=SmallDateTime#
      WHERE
      ([orderId] = #orderId,dbType=Int#)
    </update>

    <update id="SetJinDu" parameterClass="Order">
      UPDATE [dbo].[order] SET
      [schedule] = #schedule,dbType=NVarChar#
      WHERE
      ([orderId] = #orderId,dbType=Int#)
    </update>
    
		<delete id="Delete" parameterClass="Order">
			DELETE FROM [dbo].[order]
			WHERE
				([orderId] = #orderId,dbType=Int#)
		</delete>

		<select id="GetModelsByCondition" parameterClass="Hashtable" resultClass="Order">
			SELECT $columnNames$ FROM [dbo].[order] where $condition$
		</select>
		
		<select id="GetModelsByConditionByPager" parameterClass="Hashtable" resultClass="Order">
      declare @indextable table(rno int identity(1,1),nid int)
      insert into @indextable(nid) select [orderid] from [dbo].[order]
      where $condition$ order by $orderBy$

      select $columnNames$ from
      [dbo].[order] ,@indextable t
      <![CDATA[
			where t.nid= [order].orderid and t.rno>#startNo# and t.rno<=#endNo# 
      order by t.rno asc
			]]>
		</select>
		
	</statements>
</sqlMap>
